The Keyboard API, along with the useKeyboardVisible hook, allows you to interact with the software keyboard in the Scripting app. You can check the keyboard's visibility, hide it, listen for visibility changes, and access the current visibility state reactively in functional components.
The Keyboard API enables:
useKeyboardVisible hook for a reactive approach to track the keyboard's visibility.Keyboardvisible: booleantrue: The keyboard is visible.false: The keyboard is hidden.Keyboard.hide(): voidHides the keyboard if it is currently visible.
Keyboard.addVisibilityListener(listener: (visible: boolean) => void): voidAdds a listener function that is triggered whenever the keyboard's visibility changes.
Parameters:
listener: (visible: boolean) => void: A callback function that receives a visible parameter:
true: Keyboard becomes visible.false: Keyboard becomes hidden.Usage:
Keyboard.removeVisibilityListener(listener: (visible: boolean) => void): voidRemoves a previously added visibility listener.
listener: (visible: boolean) => void: The callback function to remove. It must match a function previously added with addVisibilityListener.useKeyboardVisibleuseKeyboardVisible(): booleanA hook to access the current keyboard visibility state. The hook provides a reactive way to track whether the keyboard is visible.
Returns:
true: The keyboard is currently visible.false: The keyboard is currently hidden.Usage:
Keyboard.visibleuseKeyboardVisible in a Functional ComponentuseKeyboardVisible hook in functional components for a clean and reactive way to track keyboard visibility.Keyboard.visible: Use the Keyboard.visible property for quick, non-reactive checks.addVisibilityListener as needed, and ensure you remove them when no longer required to prevent memory leaks.Keyboard.hide() method is useful for scenarios where you want to close the keyboard, such as when submitting a form or tapping outside an input field.